package com.mcms.web.control;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.mcms.service.UserService;
import com.mcms.service.common.CommonDetailCustomService;
import com.mcms.service.dw.QueryCustomService;
import com.mcms.service.fz.QueryFZCustomService;
import com.mcms.service.kf.QueryKFCustomService;
import com.mcms.service.sc.SCDetailCustomService;
import com.mcms.service.ss.QueryMZCustomService;
import com.mcms.service.xs.QueryCustomXSService;
import com.mcms.web.LoginCommand;
import com.mcms.web.vo.PageAction;

public class CustomManager extends AbstractCommandController {
	private UserService userService;

	public CustomManager() {
		setCommandClass(LoginCommand.class);
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	protected ModelAndView handle(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		
		/**参数获取*/
		String actionType = request.getParameter("actionType");// 控制跳转参数
		String userName = request.getParameter("userName");
		String deptCode = request.getParameter("deptCode");
		String customid = request.getParameter("customid");
		String pageNum = request.getParameter("pageNum");
		String numPerPage = request.getParameter("numPerPage");
		String orderField = request.getParameter("orderField");
		String orderDirection = request.getParameter("orderDirection");
		PageAction pageAction = (PageAction) request.getAttribute("pageAction");
		
		String flag = request.getParameter("flag");
		Map sessionMap = (Map) request.getSession().getAttribute("mcmsSession");
		Map paramMap = new HashMap();
		paramMap.put("customInfo", request.getParameter("customInfo"));// 客户信息：预约就诊号或者身份证号
		paramMap.put("connect", request.getParameter("connect"));// 联系方式：电话号码 或者 qq 或者 email
		paramMap.put("appointDate", request.getParameter("appointDate"));// 开始时间：分诊时间
		paramMap.put("appointDate1", request.getParameter("appointDate1"));// 截止时间：分诊时间
		paramMap.put("flag", flag);
		
		paramMap.put("pageNum", pageNum);
		paramMap.put("numPerPage", numPerPage);
		paramMap.put("orderField", orderField);
		paramMap.put("orderDirection", orderDirection);
		paramMap.put("pageAction", pageAction);
		
		
//		System.out.println("at:"+actionType+";un:"+userName+";customid:"+customid+";deptCode="+deptCode);
		
		/**登陆页跳转*/
		if(actionType!=null && actionType.trim().length()>0){
			if(actionType.equals("addCustom")){
				if(deptCode!=null && deptCode.trim().length()>0 ){
					if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息录入
						return new ModelAndView("custom/qddepart/addCustom_qd"); 
					}else if(deptCode.equalsIgnoreCase("fz")){// 分诊台的客户信息录入
						return new ModelAndView("custom/fzdepart/addCustom_fz"); 
					}else if(deptCode.equalsIgnoreCase("xs")){// 销售部的客户信息录入
						return new ModelAndView("custom/xsdepart/addCustom_xs"); 
					}else if(deptCode.equalsIgnoreCase("mz")){// 门诊部的客户信息录入
						return new ModelAndView("custom/mzdepart/addCustom_mz"); 
					}else if(deptCode.equalsIgnoreCase("kf")){// 客服部的客户信息录入
						return new ModelAndView("custom/kfdepart/addCustom_kf"); 
					}
				}
			}else if(actionType.equals("listCustom")){
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息列表查询
					
					// 客户信息列表查询
					Map resultMap = new QueryCustomService().execute(sessionMap,paramMap);
					request.setAttribute("resultMap", resultMap);
					return new ModelAndView("custom/qddepart/customList"); 
				}else if(deptCode.equalsIgnoreCase("xs")){// 销售部的客户信息查询列表
					
					// 客户信息列表查询
					Map resultMap = new QueryCustomXSService().execute(sessionMap,paramMap);
					request.setAttribute("resultMap", resultMap);
					return new ModelAndView("custom/xsdepart/customList"); 
				}else if(deptCode.equalsIgnoreCase("fz")){// 分诊台的客户信息查询列表
					
					// 客户信息列表查询
					Map resultMap = new QueryFZCustomService().execute(sessionMap, paramMap);
					request.setAttribute("resultMap", resultMap);
					return new ModelAndView("custom/fzdepart/customList"); 
				}else if(deptCode.equalsIgnoreCase("mz")){// 门诊部的客户信息查询列表
					
					// 客户信息列表查询
					Map resultMap = new QueryMZCustomService().execute(sessionMap, paramMap);
					request.setAttribute("resultMap", resultMap);
					return new ModelAndView("custom/mzdepart/customList"); 
				}else if(deptCode.equalsIgnoreCase("kf")){// 客服部的客户信息查询列表
					
					// 客户信息列表查询
					Map resultMap = new QueryKFCustomService().execute(sessionMap, paramMap);
					request.setAttribute("resultMap", resultMap);
					return new ModelAndView("custom/kfdepart/customList"); 
				}
			}else if(actionType.equals("showContent")){// 高级检索条件页展示
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息列表查询
					return new ModelAndView("custom/qddepart/advancedQuery_qd");
				}else if(deptCode.equalsIgnoreCase("xs")){// 销售部的客户信息查询列表
					return new ModelAndView("custom/xsdepart/advancedQuery_xs"); 
				}else if(deptCode.equalsIgnoreCase("fz")){// 分诊台的客户信息查询列表
					return new ModelAndView("custom/fzdepart/advancedQuery_fz");
				}else if(deptCode.equalsIgnoreCase("mz")){// 门诊部的客户信息查询列表
					return new ModelAndView("custom/mzdepart/advancedQuery_mz");
				}else if(deptCode.equalsIgnoreCase("kf")){// 客服部的客户信息查询列表
					return new ModelAndView("custom/kfdepart/advancedQuery_kf");
				}
			}else if(actionType.equals("updateCustomPage")){// 客户信息更新页面跳转
				
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息更新页面跳转
					return new ModelAndView("custom/qddepart/updateCustom_qd"); 
				}else if(deptCode.equalsIgnoreCase("fz")){// 分诊台的客户信息更新页面跳转
					return new ModelAndView("custom/fzdepart/updateCustom_fz"); 
				}else if(deptCode.equalsIgnoreCase("xs")){// 销售部的客户信息更新页面跳转
					return new ModelAndView("custom/xsdepart/updateCustom_xs"); 
				}else if(deptCode.equalsIgnoreCase("mz")){// 门诊部的客户信息更新页面跳转
					return new ModelAndView("custom/mzdepart/updateCustom_mz"); 
				}else if(deptCode.equalsIgnoreCase("kf")){// 客服部的客户信息更新页面跳转
					return new ModelAndView("custom/kfdepart/updateCustom_kf"); 
				}
			}else if(actionType.equals("detailCustomPage")){// 客户信息详细页面跳转
				
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息详细页面跳转
					// 获得并整理参数
					paramMap.put("customid", request.getParameter("customid"));
//					paramMap.put("doctorid", request.getParameter("doctorid"));
					
					// 获取客户详细信息数据
					Map map = new CommonDetailCustomService().execute(sessionMap, paramMap);
					request.setAttribute("mapResult", map);
					return new ModelAndView("custom/qddepart/detailCustom_qd"); 
				}else if(deptCode.equalsIgnoreCase("fz")){// 分诊台的客户信息详细页面跳转
					// 获得并整理参数
					paramMap.put("customid", request.getParameter("customid"));
//					paramMap.put("doctorid", request.getParameter("doctorid"));
					
					// 获取客户详细信息数据
					Map map = new CommonDetailCustomService().execute(sessionMap, paramMap);
					request.setAttribute("mapResult", map);
					return new ModelAndView("custom/fzdepart/detailCustom_fz"); 
				}else if(deptCode.equalsIgnoreCase("xs")){// 销售部的客户信息详细页面跳转
					// 获得并整理参数
					paramMap.put("customid", request.getParameter("customid"));
//					paramMap.put("doctorid", request.getParameter("doctorid"));
					
					// 获取客户详细信息数据
					Map map = new CommonDetailCustomService().execute(sessionMap, paramMap);
					request.setAttribute("mapResult", map);
					return new ModelAndView("custom/xsdepart/detailCustom_xs"); 
				}else if(deptCode.equalsIgnoreCase("mz")){// 门诊部的客户信息详细页面跳转
					// 获得并整理参数
					paramMap.put("customid", request.getParameter("customid"));
//					paramMap.put("doctorid", request.getParameter("doctorid"));
					
					// 获取客户详细信息数据
					Map map = new CommonDetailCustomService().execute(sessionMap, paramMap);
					request.setAttribute("mapResult", map);
					return new ModelAndView("custom/mzdepart/detailCustom_mz"); 
				}else if(deptCode.equalsIgnoreCase("kf")){// 客服部的客户信息详细页面跳转
					// 获得并整理参数
					paramMap.put("customid", request.getParameter("customid"));
//					paramMap.put("doctorid", request.getParameter("doctorid"));
					
					// 获取客户详细信息数据
					Map map = new CommonDetailCustomService().execute(sessionMap, paramMap);
					request.setAttribute("mapResult", map);
					return new ModelAndView("custom/kfdepart/detailCustom_kf"); 
				}
			}else if(actionType.equals("viewDoctorInfo")){// 查询客户就诊信息:单次就诊的全部记录信息1.问诊2.处置3.药物4.手术记录
				if(deptCode.equalsIgnoreCase("sc")||deptCode.equalsIgnoreCase("dw")){// 电网部和市场部的客户信息详细页面跳转
					
					// 获取参数
					
					
					return new ModelAndView("custom/qddepart/viewDoctorInfo"); 
				}
			}
		}
		
		/**默认跳转至登陆页面*/
		return new ModelAndView("login");
	}
}
